package com.ck.ck_back.controller;

import com.ck.ck_back.pojo.Result;
import com.ck.ck_back.service.collectservice;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Scanner;

@RestController
@RequestMapping("/collect")
public class CollectController {
    @Resource
    private collectservice collectserviceimpl;

    //    添加收藏，404参数错误，4无此人，3无此作品，2加入失败，1正常
    @PostMapping("/add")
    public Object add(String user_id, int production_id){
        int result = collectserviceimpl.addcollect(user_id,production_id);
        if (result == 1){
            return Result.success();
        }else if (result == 2){
            return Result.failure("加入失败");
        }else if (result == 3){
            return Result.failure("无此作品");
        }else if (result == 4){
            return Result.failure("无此人");
        }else {
            return Result.failure("参数错误");
        }
    }

    //    1正常，2失败，3无此收藏，404参数错误
    @PostMapping("/update")
    public Object update(String user_id, int production_id){
        int result = collectserviceimpl.updatecollect(user_id,production_id);
        if (result == 1){
            return Result.success();
        }else if (result == 2){
            return Result.failure("修改失败");
        }else if (result == 3){
            return Result.failure("无此记录");
        }else {return  Result.failure("参数错误");}
    }

    @PostMapping("/num")
    public Object getnum(String user_id, int production_id){
        return Result.success(collectserviceimpl.getnum(user_id,production_id));
    }

    @PostMapping("/getstate")
    public Object getstate(String user_id, int production_id){
        int result = collectserviceimpl.getstate(user_id,production_id);
        if (result == 0||result==1){
            return Result.success(result);
        }else {
            return Result.failure("参数错误");
        }
    }

    @PostMapping("/getcollect")
    public Object getfocus(String user_id){
        return Result.success(collectserviceimpl.getall(user_id));
    }

    @PostMapping("/delete")
    public Object delete(int collectId){
        int result = collectserviceimpl.deletecollect(collectId);
        if (result == 1){
            return Result.success();
        }else if (result == 2){
            return Result.failure("删除失败");
        }else if (result == 3){
            return Result.success("无此记录");
        }else {
            return Result.failure("参数错误");
        }
    }
}
